# -*- coding: utf-8 -*-
# @Time : 2022-01-25 19:24
# @Author : Z
# @Function :
import logging

# #创建一个logger日志对象
logger = logging.getLogger('./test.log')
# 设置默认的日志级别
logger.setLevel(logging.DEBUG)
# 创建日志格式对象
formatter = logging.Formatter('%(asctime)s-%(levelname)s-%(message)s')

# 创建StreamHandler对象
sh = logging.StreamHandler()
# StreamHandler对象自定义日志级别
sh.setLevel(logging.DEBUG)
# StreamHandler对象自定义日志格
sh.setFormatter(formatter)

# logger日志对象加载StreamHandler对象
logger.addHandler(sh)

# 创建FileHandler对象
fh = logging.FileHandler('./test.log')
# 创建日志格式对象
formatter = logging.Formatter('%(asctime)s-%(name)s-%(levelname)s-%(message)s')
# StreamHandler对象自定义日志级别
fh.setLevel(logging.DEBUG)
# StreamHandler对象自定义日志格
fh.setFormatter(formatter)
# logger日志对象加载StreamHandler对象
logger.addHandler(fh)

if __name__ == '__main__':
    logger.debug('nwedream')
    logger.info('nwedream')
    logger.error('nwedream')
